package com.issoft.studentresitor.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.issoft.studentresitor.domain.pojo.Clazz;
import com.issoft.studentresitor.domain.query.ClazzQuery;
import com.issoft.studentresitor.domain.vo.QueryClazzVo;
import com.issoft.studentresitor.domain.vo.StudentVo;
import com.issoft.studentresitor.mapper.ClazzMapper;
import com.issoft.studentresitor.mapper.StudentMapper;
import com.issoft.studentresitor.service.IClazzService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.issoft.studentresitor.utils.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author GJH
 * @since 2025-09-14
 */
@Slf4j
@Service
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz> implements IClazzService {
    @Autowired
    private ClazzMapper clazzMapper;
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public PageResult<QueryClazzVo> queryClazzPage(ClazzQuery clazzQuery) {
        log.info("分页查询参数：{}", clazzQuery);
        PageHelper.startPage(clazzQuery.getPage(), clazzQuery.getPageSize());
        List<QueryClazzVo> queryClazzVos = clazzMapper.queryClazzPage(clazzQuery);
        Page<QueryClazzVo> pageResult = (Page<QueryClazzVo>) queryClazzVos;
        return new PageResult<>(pageResult.getTotal(), pageResult.getResult());
    }

    @Override
    public List<StudentVo> getStudent(Integer id) {
        log.info("根据班级id查询班级内的所有学生");
        List<StudentVo> students = studentMapper.studentByClassId(id);
        if (students != null) {
            return students;
        }
        return null;
    }

    @Override
    public Long countEmptyClass() {
        log.info("统计空班级班级总数");
        return clazzMapper.countEmptyClass();
    }

    @Override
    public Clazz getByIdQuerTeaacher(Integer userId) {
        log.info("根据userId查询班级老师");
        return clazzMapper.getByIdQuerTeaacher(userId);
    }
}
